import {getStore, removeStore, setStore} from "./store";
import {getValue, remove, setValue} from "./cookie";

const TokenKey = 'x-access-token';

/**
 * 获取缓存中用户信息
 */
export function getPrincipalInStore() {
  let param = {name: "principal"};
  return getStore(param);
}

/**
 * 获取缓存中用户信息
 */
export function setPrincipalInStore(principal) {
  let param = {name: "principal", content: principal};
  return setStore(param);
}

/**
 * 移除token
 * @returns {*}
 */
export function removePrincipalInStore() {
  let param = {name: "principal"};
  return removeStore(param);
}

/**
 * 获取token
 * @returns {*}
 */
export function getTokenInCookie() {
  return getValue(TokenKey);
}

/**
 * 设置token
 * @returns {*}
 */
export function setTokenInCookie(token) {
  return setValue(TokenKey, token);
}

/**
 * 移除token
 * @returns {*}
 */
export function removeTokenInCookie() {
  return remove(TokenKey);
}
